$(".job-experience-show").hide();
/*    工作经验列表    */
var experList = new Array();
function show1() {
    $(".add-experience").css("display","block")
    $(".job-experience-show").hide();
    $(".job-experience").show();
    $(".job-exper-key").val("");
}


/********************************************保存添加工作经验 *************************************/
$(".job-expr-save").click(function () {
    $(".add-experience").css("display","none")
    $(".job-experience-show").show();
    $(".job-experience").hide();

    saveWorkExperience();
});


/***************************************ajax 添加新的工作经验****************************************/
function saveWorkExperience(){
    // var jobTime = $(".time-ipt").val();
    var startWorktime = $(".starttime").val()
    var endWorkTime = $(".endtime").val()

    var company = $(".companyname").val();
    var experJobLevel = $(".companyjob").val();
    var companySize =$(".expr-company-size option:selected").text();
    var depatement = $(".companydept").val();
    var companyType = $(".company-type").val();
    var jobDescription = $(".job-description").val();
    var jobType ;
    var experBtnList = document.querySelectorAll(".jobtype");
    // console.log("experBtnList1 :"+ experBtnList[0] );
    // console.log("experBtnList2 :"+ experBtnList[1].style);
    for (var i = 0; i < experBtnList.length; i++) {
        jobType =(experBtnList.checked == "checked"? '全职':'兼职')

    }

    console.log("job startWorktime :" + startWorktime);
    console.log("job endWorkTime :" + endWorkTime);

    console.log("company:" +  company);
    console.log("experJobLevel:" +  experJobLevel);
    console.log("companySize:" +  companySize);
    console.log("depatement:" +  depatement);

    console.log("companyType:" +  companyType);
    console.log("jobDescription:" +  jobDescription);
    console.log("jobType:" +  jobType);


    $.ajax({
        type:"post",
        url:"/workexperience",
        datatype:"json",
        data:{
            "resumeId":$(".resumeId").val(),
            "startWorktime":startWorktime,
            "endWorkTime":endWorkTime,
            "companyName":company,
            "companySize":companySize,
            "depatement":depatement,
            "jobName":experJobLevel,
            "companyType":companyType,
            "jobDescription":jobDescription,
            "jobType":jobType
        },
        success:function(result){
            console.log(result);

            if(result.status ==1){
                console.log("添加成功");
                $(".job-experience-show").show();  // 显示读取模式
                $(".job-experience").hide(); //隐藏编辑模式
                var experience = result.data;
                var experienceArr = new Array(experience)
                initExper(experienceArr);//数据显示出来
            }else{
                console.log("添加失败");
            }
        }
    })
}


$(".job-expr-unsave").click(function () {
    $(".add-experience").css("display","none")
    $(".job-experience-show").show();
    $(".job-experience").hide();
});

function initExper(experList) {


    document.querySelector(".jse-con").innerHTML = "";
    for (var i = 0; i < experList.length; i++) {
        var exper = experList[i];
        console.log("resume Id **:" + exper.resumeId)

        var time = getFormatDateYM(new Date(exper.workStartTime)) + "-" +getFormatDateYM(new Date(exper.workEndTime));
        console.log("time = " + time)
        var ssstring = "计算机软件 | " + exper.workCompanyScaler + " | " + exper.workCompanyProperty + " | " + exper.workDepartment;


        var addEle="<div class=\"experience-datail\">\n" +
            "                <input type=\"text\" class=\"work_experience_id\"  value=\"" + exper.workExperiId + "\">\n" +
            "                <input type=\"hidden\" value=\"" + i + "\">\n" +
            "                <p><span>时间：</span>" + time + " </p>\n" +
            "                <p>公司：<span>"+ exper.workCompanyName +"</span></p>\n" +
            "                <p>职位：<span>"+exper.workPosition+"</span></p>\n" +
            "                <p><span>"+ssstring+"</span></p>\n" +
            "                <p>工作描述：<span>"+ exper.workDesc +"</span></p> " +
            "                <button class=\"delete-experience\" onclick=\"getById4Update("+exper.workExperiId+")\">修改</button>\n" +
            "                <button class=\"delete-experience\" onclick=\"deleteexperience(event)\">删除</button>\n" +
            "                </div>";
        document.querySelector(".jse-con").innerHTML += addEle;
    }
}

/*********************************************点击 修改工作经验的按钮update_workexperience_btn ***********************************************/
function getById4Update(workExperienceId){
    //ajax 请求 根据当前工作经验ID 查询该id

    console.log("***************workExperienceId:"+workExperienceId);
    $.ajax({
        type:"get",
        url:"/workExperience/"+workExperienceId,
        datatype:"json",
        success:function(result){
            console.log(result);

            if(result.status ==1){
                //打开编辑模式
                //隐藏只读模式
                $(".add-experience").css("display","block")
                $(".job-experience-show").hide();
                $(".job-experience").show();
                //并且 在保存按钮上加上class="update-work-expericen-btn"

                var updateBtn = "<button  class=\"update-work_btn\" onclick=\"updateWE("+workExperienceId+ ")\">修改</button>";
                $(".job-expr-save").hide();
                $(".job-expr-btn-container").append(updateBtn);
            }
        }

    })
}

/*==============修改功能 ajax====================*/
function updateWE(workExperienceId){
    console.log("updateWE workExperienceId:"+workExperienceId);
    var startWorktime = $(".starttime").val()
    var endWorkTime = $(".endtime").val()

    var company = $(".companyname").val();
    var experJobLevel = $(".companyjob").val();
    var companySize =$(".expr-company-size option:selected").text();
    var depatement = $(".companydept").val();
    var companyType = $(".company-type").val();
    var jobDescription = $(".job-description").val();
    var jobType ;
    var experBtnList = document.querySelectorAll(".jobtype");
    // console.log("experBtnList1 :"+ experBtnList[0] );
    // console.log("experBtnList2 :"+ experBtnList[1].style);
    for (var i = 0; i < experBtnList.length; i++) {
        jobType =(experBtnList.checked == "checked"? '全职':'兼职')

    }
    $.ajax({
        type:"post",
        url:"/workexperience",
        datatype:"json",
        data:{
            _method:"put",
            "workExperienceId":workExperienceId,
            "startWorktime":startWorktime,
            "endWorkTime":endWorkTime,
            "companyName":company,
            "companySize":companySize,
            "depatement":depatement,
            "jobName":experJobLevel,
            "companyType":companyType,
            "jobDescription":jobDescription,
            "jobType":jobType
        },
        success:function(result){
            console.log(result);

            if(result.status ==1){
                console.log("修改成功");
                $(".job-experience-show").show();  // 显示读取模式
                $(".job-experience").hide(); //隐藏编辑模式
                var experience = result.data;
                var experienceArr = new Array(experience);
                initExper(experienceArr);  //数据显示出来
            }else{
                console.log("修改失败");
            }

        }
    })
}





//开启修改求职意向
function showUpdateintention(){
    document.querySelector(".error-tip").style.display="none";
    document.querySelector(".intention-datil").style.display="block";
}
function updateintention() {
    var salaryselect=document.getElementById("salary-type");
    var index=salaryselect.selectedIndex ;
    var timeselect=document.getElementById("work-time");
    var index1=timeselect.selectedIndex ;
    var typeselect=document.getElementById("work-type");
    var index2=typeselect.selectedIndex ;

    if (document.querySelector(".salary-input").value!=""&&document.querySelector(".address-input").value!=""
        &&document.querySelector(".job-input").value!="") {
        var addEle="<p>期望薪资：${salaryselect.options[index].value}<span>${document.querySelector(\".salary-input\").value}</span></p>\n" +
            "                <p>工作地点：<span>${document.querySelector(\".address-input\").value}</span></p>\n" +
            "                <p>期望职位：<span>${document.querySelector(\".job-input\").value}</span></p>\n" +
            "                <p>到岗时间：<span>${timeselect.options[index1].value}</span></p>\n" +
            "                <p>工作类型：<span>${typeselect.options[index2].value}</span></p>";
        document.querySelector(".update-intention-div").innerHTML=addEle;

        document.querySelector(".intention-datil").style.display="none";
    }else {
        document.querySelector(".error-tip").style.display="block";
    }
}


//关闭修改求职意向
function closeupdateintention() {
    document.querySelector(".intention-datil").style.display="none";
}
